import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'

export const constantRoutes: Array<RouteRecordRaw> = [
    {//用户管理、部门管理、角色管理、菜单管理、日志管理、数据字典管理、文件管理、图表展示
        path: '/main',
        name: 'main',
        component: () => import('../components/HomeView.vue'),
        redirect: '/UserManagement',
        children: [
            {
                name: "UserManagement",
                path: "/UserManagement",
                component: () => import('../components/AccessManagement.vue'),
                meta: {
                    title: "访客管理",
                    icon: "User"
                },
                children: []
            },

            {
                name: "LandmarkManagement",
                path: "/LandmarkManagement",
                component: () => import('../components/LandmarkManagement.vue'),
                meta: {
                    title: "地标管理",
                    icon: "Service"
                },
                children: []
            },

            {
                name: "DataShow",
                path: "/DataShow",
                component: () => import('../components/DataShow.vue'),
                meta: {
                    title: "数据统计",
                    icon: "Odometer"

                },
                children: []
            },
            // {
            //     name: "GraphicPresentation",
            //     path: "/GraphicPresentation",
            //     component: () => import('../components/AccessManagement.vue'),
            //     meta: {
            //         title: "图表展示",
            //         icon: "DataAnalysis"
            //     },
            //     children: []
            // },
        ]
    },
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('../components/login.vue'),
        children: []
    },
    {
        path: '/:catchAll',
        name: '/404',
        component: () => import('../components/404.vue'),
        children: []
    },

]


export const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    linkActiveClass: 'router-checked',
    routes: constantRoutes
})


// 白名单
//const whiteList = ['/login'] // no redirect whitelist
export const permissionsList = ['/Home', '/login', '/HomePage', '/main'] // no redirect whitelist
router.beforeEach((to, from, next) => {
    next()
    /*  if (getToken() != undefined && permissionsList.indexOf(to.path) !== -1) {
          next()
          //没有token并且是前往login页面
      } else if (getToken() == undefined && whiteList.indexOf(to.path) !== -1) {
          // 未登录,跳转到登陆页面
          next()
      } else {
          next({
              path: '/login'
          })
      }*/
})
export default router
